package hello.error;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;

@Controller
public class ErrorCustomConfig implements ErrorController {
    private static final String ERROR_PATH = "/error";

    @RequestMapping(value = ERROR_PATH)
    private String handleError(HttpServletResponse response) {
        int httpStatus = response.getStatus();
        switch (httpStatus) {
            case 400:
                return "/error/400";
            case 401:
                return "/error/401";
            case 403:
                return "/error/403";
            case 404:
                return "/error/404";
            case 500:
                return "/error/500";
            default:
                break;
        }
        return "/swagger-ui.html";
    }

    @Override
    public String getErrorPath() {
        return ERROR_PATH;
    }

}